<!-- filepath: c:\Work\JxcNew\Code\webfront\ClientWebFront\src\public\views\componentsWeb\QualityInputCell.vue -->
<template>
  <el-input
    :model-value="commodityBatch.count.value"
    @update:modelValue="handlePriceInput"
    type="number"
    :min="0"
    :step="decimalAllowed ? 0.1 : 1"
    @blur="handleBlur"
    style="width: 100%"
  />
</template>

<script>
import { CsDouble } from '../../engine/common/csDouble';
export default {
  name: 'QualityInputCell',
  props: {
    decimalAllowed: {
      type: Boolean,
      default: true
    },
    // commodityBatch 可能是  commodityBatch 也可能是 commodityBatchTax
    commodityBatch: {
      type: Object, // 传入整个商品批次对象
      required: true
    }
  },
  methods: {
    handlePriceInput(value) {
      let numValue = Number(value);
      if (isNaN(numValue) || value === '' || numValue < 0) numValue = 0;


      // 修改商品批次对象的单价
      this.commodityBatch.setCount(new CsDouble(numValue));     
    },
    handleBlur(event) {
      // 可选：失焦时做进一步校验或格式化
      this.handlePriceInput(event.target.value);
    }
  }
};
</script>

<style scoped>
:deep(.el-input__inner) {
  text-align: right;
}
</style>